<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<div class="page-breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="fa fa-home"></i>
            <a href="#">Home</a>
        </li>
        <li class="active">用户管理</li>
    </ul>
</div>
<div class="page-body">
    <div class="row">
        <div class="col-xs-12 col-md-12">
            <div class="widget">
                <div class="widget-header bordered-bottom bordered-themeprimary">
                    <i class="widget-icon fa fa-tasks themeprimary"></i>
                    <span class="widget-caption themeprimary">用户列表</span>
                    <a id="editabledatatable_new" href="#!user/add" class="btn btn-sm themeprimary pull-right">新建用户</a>
                </div>
                <div class="widget-body">
                    <table id="dt_basic" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th data-class="phone,tablet">编号ID</th>
                            <th data-class="expand">名称</th>
                            <th data-hide="phone">电话号码</th>
                            <th data-hide="phone">邮箱</th>
                            <th data-hide="phone">备注</th>
                            <th data-hide="phone">创建时间</th>
                            <th data-hide="phone">操作</th>
                        </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>
<script type="application/javascript">
    var oTable;
    $(function(){
        oTable = $('#dt_basic').dataTable({
            serverSide: true,
            orderMulti: false,
            sDom: "Tflt<'row DTTTFooter'<'col-sm-6'i><'col-sm-6'p>>",
            "oTableTools": {
                "aButtons": []
            },
            "language": {
                "search": "",
                'emptyTable': '没有数据',
                'loadingRecords': '加载中...',
                'processing': '查询中...',
                'sLengthMenu': '每页 _MENU_ 件',
                'zeroRecords': '没有数据',
                "oPaginate": {
                    "sPrevious": "上一页",
                    "sNext": "下一页"
                },
                //'info': '当前显示 _START_ 到 _END_ 条记录,共 _TOTAL_ 条记录,共 _PAGES_页,当前第_PAGE_ 页',
                'info': '当前显示 _START_ 到 _END_ 条记录,共 _TOTAL_ 条记录',
                'infoEmpty': '没有数据',
                'infoFiltered': '(过滤总件数 _MAX_ 条)'
            },
            bProcessing: true,
            columns: [
                { "data": "id" },
                { "data": "name" },
                { "data": "phone" },
                { "data": "email" },
                { "data": "note" },
                { "data": "createTime",
                    "render":function(data, type, full, meta){
                        return TimeUtil.yyyyMMddHHmmss(data);
                    }
                },
                { "data": "id" , "bSortable": false ,
                    "render":function(data, type, full, meta){
                        var tmp =
                                '<a href="#!system/role/role-update.html?target='+window.btoa(data)+'" class="btn btn-info btn-xs edit"><i class="fa fa-edit"></i> 修改</a> '
                                +'<a href="javascript:delData(&quot;'+window.btoa(data)+'&quot;);" class="btn btn-danger btn-xs delete"><i class="fa fa-trash-o"></i> 删除</a>'

                                +'<div class="btn-group" style="margin-left: 5px;">                                                '
                                +'	<a class="btn btn-xs btn-maroon dropdown-toggle" data-toggle="dropdown">   '
                                +'		更多 <i class="fa fa-angle-down"></i>                          '
                                +'	</a>                                                                 '
                                +'	<ul class="dropdown-menu">                                           '
                                +'		<li>                                                             '
                                +'			<a href="#!system/role/role-menu.html?target='+window.btoa(data)+'">查看菜单</a>                     '
                                +'		</li>                                                            '
                                +'		<li>                                                             '
                                +'			<a href="javascript:modifyHptDialog(&quot;'+window.btoa(data)+'&quot;);">查看功能</a>             '
                                +'		</li>                                                            '
                                +'	</ul>                                                                '
                                +'</div>';
                        return tmp;
                    }
                }
            ],
            aaSorting: [],
            ajax: function (data, callback, settings) {
                var param = {};
                param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                param.start = data.start;//开始的记录序号
                param.page = (data.start / data.length) + 1;//当前页码
                param.name=data.search['value'];

                $.ajax({
                    type: "GET",
                    url: "user/query/"+param.page+"/"+param.limit,
                    cache: false, //禁用缓存
                    data: param, //传入组装的参数
                    dataType: "json",
                    success: function (content) {
                        var result = content.result;
                        if(null != content.result){
                            var returnData = {};
                            returnData.draw=result.content;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.totalSize;//返回数据全部记录
                            returnData.recordsFiltered = result.totalSize;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.content;//返回的数据列表
                            callback(returnData);
                        }
                    }
                });
            }
        });

        $('.dsearch').on('keyup click', function () {
            var tsval = $(".dsearch").val()
            $('#dt_basic').search(tsval, false, false).draw();
        });
    });

    function delData(id){
        layer.confirm('你真的要删除该数据吗?', {
            btn: ['删除','取消']
        }, function(index, layero){
            $.ajax({
                type:"DELETE",
                headers: {
                    "Content-Type": "application/json",
                    "X-HTTP-Method-Override": "DELETE"
                }, //PUT,DELETE
                url:"user/"+window.atob(id),
                success:function(response){
                    layer.close(index);
                    Notify(response.message, 'top-right', '800', 'success', 'fa-bolt', true);
                    oTable.fnReloadAjax();
                },
                error: function(error) {
                    var obj = jQuery.parseJSON(error.responseText);
                    Notify(obj.message, 'top-right', '800', 'warning', 'fa-bolt', true);
                }
            });
        });
    }

</script>